package dontCare.gwtester.client.gwt.style;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import dontCare.gwtester.client.tool.SourceUrl;
import dontCare.gwtester.client.tool.UnitWidget;

public class StyleNameTest extends UnitWidget  {
	private static StyleNameTestUiBinder uiBinder = GWT.create(StyleNameTestUiBinder.class);
	interface StyleNameTestUiBinder extends 
		UiBinder<Widget, StyleNameTest> {
	}

	public StyleNameTest() {
		initWidget(uiBinder.createAndBindUi(this));
		showStyles();
	}
	
	@UiField Button initStyle;
	@UiField Button addStyleRed;
	@UiField Button addStyleGreen;
	@UiField Button addStyleBlue;
	@UiField Button removeStyleRed;
	@UiField Button removeStyleGreen;
	@UiField Button removeStyleBlue;
	@UiField Button setStyleRed;
	@UiField Button setStyleGreen;
	@UiField Button setStyleBlue;
	@UiField Button setPrimaryStyleRed;
	@UiField Button setPrimaryStyleGreen;
	@UiField Button setPrimaryStyleBlue;
	
	@UiField HTMLPanel styleTarget;
	@UiField Label showCssClass;

	@UiHandler("initStyle") void clickInitStyle(ClickEvent e){
		styleTarget.setStyleName("");
		showStyles();
	}
	@UiHandler("setStyleRed") void clickSetStyleRed(ClickEvent e){
		styleTarget.setStyleName("bgRed");
		showStyles();
	}
	@UiHandler("setStyleGreen") void clickSetStyleGreen(ClickEvent e){
		styleTarget.setStyleName("bgGreen");
		showStyles();
	}
	@UiHandler("setStyleBlue") void clickSetStyleBlue(ClickEvent e){
		styleTarget.setStyleName("bgBlue");
		showStyles();
	}
	@UiHandler("addStyleRed") void clickAddStyleRed(ClickEvent e){
		styleTarget.addStyleName("bgRed");
		showStyles();
	}
	@UiHandler("addStyleGreen") void clickAddStyleGreen(ClickEvent e){
		styleTarget.addStyleName("bgGreen");
		showStyles();
	}
	@UiHandler("addStyleBlue") void clickAddStyleBlue(ClickEvent e){
		styleTarget.addStyleName("bgBlue");
		showStyles();
	}
	@UiHandler("removeStyleRed") void clickRemoveStyleRed(ClickEvent e){
		styleTarget.removeStyleName("bgRed");
		showStyles();
	}
	@UiHandler("removeStyleGreen") void clickRemoveStyleGreen(ClickEvent e){
		styleTarget.removeStyleName("bgGreen");
		showStyles();
	}
	@UiHandler("removeStyleBlue") void clickRemoveStyleBlue(ClickEvent e){
		styleTarget.removeStyleName("bgBlue");
		showStyles();
	}
	
	@UiHandler("setPrimaryStyleRed") void clickAddPrimaryStyleRed(ClickEvent e){
		styleTarget.setStylePrimaryName("bgRed");
		showStyles();
	}
	@UiHandler("setPrimaryStyleGreen") void clickAddPrimaryStyleGreen(ClickEvent e){
		styleTarget.setStylePrimaryName("bgGreen");
		showStyles();
	}
	@UiHandler("setPrimaryStyleBlue") void clickAddPrimaryStyleBlue(ClickEvent e){
		styleTarget.setStylePrimaryName("bgBlue");
		showStyles();
	}
	
	private void showStyles(){
		showCssClass.setText("<div class='" + styleTarget.getStyleName() +"'></div>");	
	}
	
	@Override
	public List<String> getSourceUrl() {
		ArrayList<String> result = new ArrayList<String>();
		result.add(SourceUrl.genJava(StyleNameTest.class));
		result.add(SourceUrl.genUiXml(StyleNameTest.class));
		return result;
	}

	@Override
	public HTML getDescription() {
		return new HTML("<a href='http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/user/client/ui/UIObject.html'>Widget 的屬性</a>測試");
	}
	@Override
	public String getName() {
		return "StyleName 測試";
	}

}
